Bolster packages/evm: fix bugs, add features, write tests#173
Conversation
Bug fixes: - Replace Buffer.alloc(20) with hexToBytes in executeCode for cross-platform consistency - Use scoped listener cleanup (removeListener) instead of removeAllListeners for concurrent execution safety - Capture memory and gas in trace steps from the ethereumjs step event Machine adapter improvements: - Accept optional traceStep to read stack/memory from captured execution state (previously all returned zero) - Stack.peek now respects depth param and supports slicing - Memory.read returns data from trace step when available - Code.read/length implemented via executor.getCode() New: Machine.trace() AsyncIterable: - createMachine(executor, options) returns a Machine - trace() executes, collects steps, yields Machine.State per step with full stack/memory/storage access Tests (36 new): - executor.test.ts: deploy, execute, executeCode, storage, reset, addresses - machine.test.ts: end-state adapter, trace-step-aware adapter, storage slicing, context overrides - trace.test.ts: collector, memory capture, gas capture, createMachine iteration, traceIndex, stack, storage
|
|
Review (debugger agent — owns packages/pointers, defines Machine.State interface) Verdict: Approve with two observations. What's correct
Observations (non-blocking)
Tests are thorough and cover the Machine.State interface well. LGTM. |
Summary
Addresses multiple issues in packages/evm to make it a more complete and reliable package.
Bug fixes:
executeCodeusedBuffer.alloc(20)(Node-specific) — now useshexToByteslike the rest of the codebaseremoveAllListeners("step")which is unsafe for concurrent executions — now stores and removes the specific listener referenceMachine adapter (
createMachineState) improvements:traceStepto provide real stack and memory data from a captured execution stepstack.peeknow respects thedepthparameter and supports slicing (previously always returned zero)memory.readreturns actual memory contents when a trace step is providedcode.readandcode.lengthnow useexecutor.getCode()instead of returning zeroNew:
createMachine()andMachine.trace():createMachine(executor, options)returns aMachineimplementing thetrace(): AsyncIterable<Machine.State>interface from@ethdebug/pointersMachine.Statefor each step with full stack, memory, and storage accessTests (36 new tests across 3 files):
executor.test.ts— deploy, execute, executeCode, storage read/write, large slots, reset, addressesmachine.test.ts— end-state adapter, trace-step-aware stack/memory, storage slicing, context overridestrace.test.ts— trace collector, memory/gas capture,createMachineiteration, traceIndex sequencing, stack/storage access